<template>
  <div
    class="carousel"
    v-bind:style="{
      opacity: componentOpacity,
    }"
  >
    <n-Carousel
      :slides-per-view="4"
      :space-between="20"
      :loop="true"
      :interval="3000"
      :autoplay="true"
      draggable
    >
      <div v-for="(item, index) in piclist" :key="index">
        <img class="carousel-img" :src="item.src" />
        <h2>{{ item.description }}</h2>
      </div>
    </n-Carousel>
  </div>
</template>

<script lang="ts">
import { Ref, ref } from "vue";
class CarouselItem {
  src: string;
  description: string;
  constructor(src: string, description: string) {
    this.src = src;
    this.description = description;
  }
}
export default {
  name: "Carousel",
  props:['componentOpacity'],
  setup() {
    const piclist: Ref<CarouselItem[]> = ref([
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "描述"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "细节"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "图源"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "更替"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "交互"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "滑动"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "定时"
      ),
      new CarouselItem(
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.aiimg.com%2Fuploads%2Fallimg%2F190329%2F263915-1Z32ZK5290-L.jpg&refer=http%3A%2F%2Fimg.aiimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651817722&t=267fbb45320231271e62da9d553a1929",
        "回弹"
      ),
    ]);
    return {
      piclist,
    };
  },
};
</script>

<style scoped>
.carousel {
  padding: 5% 10%;
  display: flex;
  justify-content: center;
}
.carousel-img {
  width: 240px;
  height: 240px;
  border-radius: 50%;
  object-fit: cover;
}
</style>